A search feature can be interesting for interaction
And very useful to confirm geolocation data
# Loading an extra package (which cointains the function we want)install.packages('leaflet.extras')library(leaflet.extras)# Adding the searchOSM featurecps_schools |>leaflet() |>addProviderTiles("CartoDB") |>addCircleMarkers(lng =~school_long,lat =~school_lat,radius =5,color ="red",label =~school_nm) |>addSearchOSM()
leaflet: group creation
A search feature can be interesting for interaction
And very useful to confirm geolocation data
## Changing the mapping method# And adding the `color` and `group` parameters within the callsleaflet() |>addProviderTiles("CartoDB") |>addCircleMarkers(lng = cps_schools_blue$school_long,lat = cps_schools_blue$school_lat,radius =5,color ='blue',group ='selected',label = cps_schools_blue$school_nm) |>addCircleMarkers(lng = cps_schools_red$school_long,lat = cps_schools_red$school_lat,radius =5,color ='red',group ='control',label = cps_schools_red$school_nm) |>addSearchOSM()
leaflet: clustering
When we have too much data (too much points), the map can get crowded, and a good option to solve this is to cluster the points!
# Reading a shape file with `st_read` from the sf packagelibrary(sf)chicago_districs <-st_read('chicago-boundaries/chciago_shape.shp')## Clustering the points in the graphleaflet() |>addProviderTiles("CartoDB") |>addCircleMarkers(lng = cps_schools_blue$school_long,lat = cps_schools_blue$school_lat,radius =5,color ="blue",group ='selected',label = cps_schools_blue$school_nm,clusterOptions =markerClusterOptions()) |>addCircleMarkers(lng = cps_schools_red$school_long,lat = cps_schools_red$school_lat,radius =5,color ="red",group ='control',label = cps_schools_red$school_nm,clusterOptions =markerClusterOptions()) |>addSearchOSM() |>## Adding the shape file as the final layeraddPolygons(data = chicago_districs,weight =2,opacity =0.5,color ='orange',dashArray ='3',fillOpacity =0.2)